﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Linq.Expressions;
using VelocityCMS.Controllers;
using VelocityCMS.Domain;

namespace VelocityCMS.Views.Test
{
    public partial class PageDisplay : ViewPage<PageDTO>
    {
        public void Page_Load()
        {
            foreach (ComponentDTO cdto in ViewData.Components)
            {
                ComponentHolder.Text = ComponentHolder.Text + RenderComponent(c => c.Index(cdto.Name, cdto));
            }      
        }

        public string RenderComponent(Expression<Action<VelocityComponentsController>> action)
        {
            var controller = new VelocityComponentsController();
            controller.Context = this.ViewContext;
            var ex = action.Compile();
            ex.Invoke(controller);
            return controller.RenderedHtml;
        }

    }
}
